<?php
namespace app\models;

use yii\base\Model;
use yii\web\UploadedFile;

class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $imageFile;

    public function rules()
    {
        return [

        ];
    }

    public function upload(){
        if ($this->validate()) {
            $pathurl='uploads/'.date('Y-m-d');
            if (!file_exists($pathurl)) {
                mkdir($pathurl,0777,true);
            }
            $path=$pathurl.'/'.md5(uniqid(6).$this->imageFile->baseName).'.'.$this->imageFile->extension;
            $this->imageFile->saveAs($path);
            return ['code'=>1,'url'=>'/'.$path];
        } else {
            return ['code'=>0];
        }
    }



}